function zz(obj) {
    str = ''
    for (var key in obj) {
        str += `${key}=${obj[key]}&`
    }
    return str.slice(0, str.length - 1)
}
function ajax(a, url, canshu) {
    return new Promise((resolve, reject) => {
        //1.创建对象
        var xhr = new XMLHttpRequest()
        //2.配置对象
        xhr.open(a, a == 'get' ? url + '?' + zz(canshu) : url)
        //3.配置回调函数
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                //字符串转对象
                resolve(JSON.parse(xhr.responseText))
            }
        }
        //4.发送
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send(a == 'get' ? null : zz(canshu))
    })
}
